///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_OS_CAPPLICATION_H_
#define _BUOLA_OS_CAPPLICATION_H_

//#include <buola/system.h>
#include <buola/io/curi.h>
#include <set>

namespace buola { namespace os {

////////////////////////////////////////////////////////////////////
/////////////////////// Class CApplication /////////////////////////
////////////////////////////////////////////////////////////////////
//
// This class represents an application, and its abilities to open
// mime types and different actions supported
//
////////////////////////////////////////////////////////////////////

class CApplication
{
private:
    CApplication(const io::CURI &pURI,const std::string &pIDName);

public:
//interface
    const io::CURI &GetURI()                {   return mURI;            }
    const std::string &GetIDName()          {   return mIDName;         }
    const std::wstring &GetName()           {   return mName;           }
    const std::wstring &GeyGenericName()    {   return mGenericName;    }
    const std::wstring &GetComment()        {   return mComment;        }
    bool ShouldDisplay()                {   return !mNoDisplay;     }
    const std::string &GetIcon()            {   return mIcon;           }
    const std::string &GetExec()            {   return mExec;           }
    const std::string &GetPath()            {   return mPath;           }
    bool GetTerminal()                  {   return mTerminal;       }
    bool HasMimeType(const std::string &pMimeType)  {   return mMimeTypes.count(pMimeType);    }
    bool HasCategory(const std::string &pCategory)  {   return mCategories.count(pCategory);    }
    bool GetStartupNotify()             {   return mStartupNotify;  }
    const std::string &GetWMClass()         {   return mWMClass; }
    void Run();
    const std::vector<CAppAction*> &GetActions()    {   return mActions;    }

public:
    static CApplication *LoadApp(const io::CURI &pPath,const std::string &pIDName);
    static void AddAllInFolder(const io::CURI &pPath,std::set<CApplication*> &pDst);
    static CApplication *Get(const std::string &pIDName);
    static CApplication *Get(const std::string &pIDName,const io::CURI &pBasePath);
    static void LoadDefaultPaths();
    
    static CApplication *GetByClass(const std::string &pClass);

private:
    io::CURI mURI;

    std::string mIDName;
    
    std::wstring mName;
    std::wstring mGenericName;
    std::wstring mComment;
    bool mNoDisplay;
    std::string mIcon;
    bool mDeleted; //called Hidden in the specification
    std::string mExec;
    std::string mPath;
    bool mTerminal;
    std::set<std::string> mMimeTypes;
    std::set<std::string> mCategories;
    bool mStartupNotify;
    std::string mWMClass;
    
    std::vector<CAppAction*> mActions;
};

/*namespace os*/ } /*namespace buola*/ }

#endif
